package com.sitanyun.merchant.guide.view.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sitanyun.merchant.guide.R;
import com.sitanyun.merchant.guide.base.BaseActivity;
import com.sitanyun.merchant.guide.base.XFragment;
import com.sitanyun.merchant.guide.frament.UserFragment;
import com.sitanyun.merchant.guide.frament.view.fragment.MyusersFrament;
import com.sitanyun.merchant.guide.frament.view.fragment.ScenHomeFrament;

import androidx.fragment.app.FragmentTransaction;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 场景
 */
public class SceneActivity extends BaseActivity {


    @BindView(R.id.sce_frament)
    FrameLayout sceFrament;
    @BindView(R.id.im_home)
    ImageView imHome;
    @BindView(R.id.tv_home)
    TextView tvHome;
    @BindView(R.id.ll_sce_home)
    LinearLayout llSceHome;
    @BindView(R.id.im_user)
    ImageView imUser;
    @BindView(R.id.tv_user)
    TextView tvUser;
    @BindView(R.id.ll_sce_members)
    LinearLayout llSceMembers;
    @BindView(R.id.im_my)
    ImageView imMy;
    @BindView(R.id.tv_my)
    TextView tvMy;
    @BindView(R.id.ll_sce_my)
    LinearLayout llSceMy;
    @BindView(R.id.ll_bottom)
    LinearLayout llBottom;
    private XFragment[] mFragments;
    private int index;
    private int currentTabIndex;
    @Override
    public int getLayoutId() {
        return R.layout.activity_scene;
    }

    @Override
    public void initData(Bundle savedInstanceState) {
    }

    @Override
    public void initView() {
        ScenHomeFrament homeFragment = new ScenHomeFrament();
        UserFragment myusersFrament = new UserFragment();
        MyusersFrament myFragment = new MyusersFrament();
        mFragments = new XFragment[]{homeFragment, myusersFrament, myFragment};
      int id=   getIntent().getIntExtra("id",0);
       if (id==2){
           llBottom.setVisibility(View.GONE);
           getSupportFragmentManager().beginTransaction().add(R.id.sce_frament, myusersFrament)
                   .add(R.id.sce_frament, homeFragment).add(R.id.sce_frament, myFragment)
                   .hide(homeFragment).hide(myFragment).show(myusersFrament)
                   .commit();
       }else {

           getSupportFragmentManager().beginTransaction().add(R.id.sce_frament, homeFragment)
                   .add(R.id.sce_frament, myusersFrament).hide(myusersFrament).show(homeFragment)
                   .commit();
       }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
    @OnClick({R.id.ll_sce_home, R.id.ll_sce_members, R.id.ll_sce_my})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_sce_home:
                index = 0;
                imHome.setBackgroundResource(R.mipmap.scenx);
                tvHome.setTextColor(getResources().getColor(R.color.biue));
                imUser.setBackgroundResource(R.mipmap.userw);
                tvUser.setTextColor(getResources().getColor(R.color.color_text_color));
                imMy.setBackgroundResource(R.mipmap.my_wei);
                tvMy.setTextColor(getResources().getColor(R.color.color_text_color));
                break;
            case R.id.ll_sce_members:
                index = 1;
                imHome.setBackgroundResource(R.mipmap.scenw);
                tvHome.setTextColor(getResources().getColor(R.color.color_text_color));
                imUser.setBackgroundResource(R.mipmap.userx);
                tvUser.setTextColor(getResources().getColor(R.color.biue));
                imMy.setBackgroundResource(R.mipmap.my_wei);
                tvMy.setTextColor(getResources().getColor(R.color.color_text_color));
                break;
            case R.id.ll_sce_my:
                index = 2;
                imHome.setBackgroundResource(R.mipmap.scenw);
                tvHome.setTextColor(getResources().getColor(R.color.color_text_color));
                imUser.setBackgroundResource(R.mipmap.userw);
                tvUser.setTextColor(getResources().getColor(R.color.color_text_color));
                imMy.setBackgroundResource(R.mipmap.my_xuan);
                tvMy.setTextColor(getResources().getColor(R.color.biue));
                break;
        }
        if (currentTabIndex != index) {
            FragmentTransaction trx = getSupportFragmentManager().beginTransaction();
            trx.hide(mFragments[currentTabIndex]);
            if (!mFragments[index].isAdded()) {
                trx.add(R.id.sce_frament, mFragments[index]);
            }
            trx.show(mFragments[index]).commit();
        }
        currentTabIndex = index;

    }

}
